<?php
/**
 * 功能描述：此接口用于发送短信内容到指定的手机
 *
 * 作者：zenan.li
 *
 * Created by Zend Studio.
 * User: zenan.li (FDG348)
 * Date: 2017/9/5
 * Time: 15:39
 */

namespace common\helps;

use Yii;


class api
{
    public static function post($action, $data=null)
    {
        $data = $data ? http_build_query($data) : null;
        $url = Yii::$app->params['API_PATH'] . $action;
        $postUrl = $url;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);
        if ($data) {
            $data = json_decode($data, 1);
        } else {
            $data = array('msg' => '接口错误', 'code' => 500, 'data' => null);
        }
        return $data;
    }
}